package com.struc.td;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

public class Pause extends State{
	private Main main;
	private Texture pauseScreen;
	private Sprite bg;
	private SpriteBatch sb;
	private Sprite pauseButton;
	private Sprite soundButton;
	private Sprite soundOnButton;
	private Sprite soundOffButton;
	private Sprite backToMain;
	private Sprite restartBut;

	public Pause(Main m) {
		pauseButton = new Sprite(StaticTextures.playbutton);
		backToMain = new Sprite(StaticTextures.pausemenu, 119, 81, 294, 84);
		restartBut = new Sprite(StaticTextures.pausemenu, 119, 180, 290, 84);
		soundOnButton = new Sprite(StaticTextures.soundon);
		soundOffButton = new Sprite(StaticTextures.soundoff);
		pauseScreen = StaticTextures.pauseScreen;
		bg = new Sprite(pauseScreen, 0, 0, 512, 512);
		sb = new SpriteBatch();
		main = m;
	}
	// makes sure the menu is where it should be.
	public void update() {
		bg.setBounds(0,0,Gdx.graphics.getWidth(),Gdx.graphics.getHeight());
		backToMain.setBounds(Gdx.graphics.getWidth()/2-75, Gdx.graphics.getHeight()-100, 150, 35);
		restartBut.setBounds(Gdx.graphics.getWidth()/2-75, Gdx.graphics.getHeight()-150, 150, 35);
		pauseButton.setBounds(0,Gdx.graphics.getHeight()-30,30,30);
		soundOnButton.setBounds(0,Gdx.graphics.getHeight()-60,30,30);
		soundOffButton.setBounds(0,Gdx.graphics.getHeight()-60,30,30);
		if(Sounds.getMuted()){
			soundButton = soundOffButton;
		}
		else{
			soundButton = soundOnButton;
		}
	}
	// Renders the pause menu.
	public void render() {
		main.getState(2).render();
		sb.begin();
		bg.draw(sb);
		backToMain.draw(sb);
		restartBut.draw(sb);
		pauseButton.draw(sb);
		soundButton.draw(sb);
		sb.end();
	}

	public void enter() {
		Gdx.input.setInputProcessor(this);
	}

	public boolean keyDown(int arg0) {
		return false;
	}

	public boolean keyTyped(char arg0) {
		return false;
	}

	public boolean keyUp(int arg0) {
		return false;
	}

	public boolean scrolled(int arg0) {
		return false;
	}

	public boolean touchDown(int x, int y, int arg2, int arg3) {
		y = Gdx.graphics.getHeight()-y;
		if (pauseButton.getBoundingRectangle().contains(x,y)) {
			main.setState(2);
		}
		if (backToMain.getBoundingRectangle().contains(x,y)) {
			main.setState(1);
			
		}
		if (restartBut.getBoundingRectangle().contains(x,y)) {
			restartGame();
		}
		if (soundButton.getBoundingRectangle().contains(x,y)) {
			Sounds.mute();
			
		}
		return false;
	}

	public void restartGame(){
		((Game) main.getState(2)).restart();
		main.setState(2);
	}
	
	public boolean touchDragged(int arg0, int arg1, int arg2) {
		return false;
	}

	public boolean touchMoved(int arg0, int arg1) {
		return false;
	}

	public boolean touchUp(int arg0, int arg1, int arg2, int arg3) {
		return false;
	}

}
